package ru.nsu.ccfit.shumkina.algorithm.world;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Вера
 * Time: 17:30
 * To change this template use File | Settings | File Templates.
 */
public class Settings {
    int latinPageSymbolsMax = 200;
    int cyrillicPageSymbolsMax = 100;
    int itemsPerPageMax = 8;
    boolean useMoreButton = false;
    List<String> morePatterns = Arrays.asList("Еще", "More", "Далее"); // first cyrillic alternative will be used
                    // for cyrillic pages more button adding, first latin - for latin
    int morePopularityPercentThreshold = 0;
    int adaptationPopularityThreshold = 1;
    int adaptationLengthThreshold = 2;

    ArrayList<String> themeRoots = null;
    ArrayList<String> fixedRoots = null;

    public int getLatinPageSymbolsMax() {
        return latinPageSymbolsMax;
    }

    public void setLatinPageSymbolsMax(int latinPageSymbolsMax) {
        if (latinPageSymbolsMax < 1) {
            System.out.printf("WARNING: Bad maximum latin symbols on page value: %d, default value of 160 will be used instead.\n",
                    latinPageSymbolsMax);
            this.latinPageSymbolsMax = 160;
            return;
        }
        this.latinPageSymbolsMax = latinPageSymbolsMax;
    }

    public int getCyrillicPageSymbolsMax() {
        return cyrillicPageSymbolsMax;
    }

    public void setCyrillicPageSymbolsMax(int cyrillicPageSymbolsMax) {
        if (cyrillicPageSymbolsMax < 1 ) {
            System.out.printf("WARNING: Bad maximum cyrillic symbols on page value: %d, default value of 70 will be used instead.\n",
                    cyrillicPageSymbolsMax);
            this.cyrillicPageSymbolsMax = 70;
            return;
        }
        this.cyrillicPageSymbolsMax = cyrillicPageSymbolsMax;
    }

    public int getItemsPerPageMax() {
        return itemsPerPageMax;
    }

    public void setItemsPerPageMax(int itemsPerPageMax) {
        if (itemsPerPageMax < 1 || itemsPerPageMax > 9) {
            System.out.printf("WARNING: Bad maximum of items on page: %d%%, default value of 8 will be used instead.\n",
                    itemsPerPageMax);
            this.itemsPerPageMax = 8;
            return;
        }
        this.itemsPerPageMax = itemsPerPageMax;
    }

    public boolean isUseMoreButton() {
        return useMoreButton;
    }

    public void setUseMoreButton(boolean useMoreButton) {
        this.useMoreButton = useMoreButton;
    }

    public List<String> getMorePatterns() {
        return morePatterns;
    }

    public void setMorePatterns(List<String> morePatterns) {
        if (morePatterns.isEmpty()) {
            System.out.printf("WARNING: No patterns for 'More' shortcut found, default patterns will be used instead.\n");
            morePatterns = Arrays.asList("Еще", "More", "Далее");
            return;
        }
        this.morePatterns = morePatterns;
    }

    public int getMorePopularityPercentThreshold() {
        return morePopularityPercentThreshold;
    }

    public void setMorePopularityPercentThreshold(int morePopularityPercentThreshold) {
        if (morePopularityPercentThreshold < 0) {
            System.out.printf("WARNING: Bad 'More' popularity threshold: %d%%, default value of 0%% will be used instead.\n",
                    morePopularityPercentThreshold);
            this.morePopularityPercentThreshold = 1;
            return;
        }
        this.morePopularityPercentThreshold = morePopularityPercentThreshold;
    }

    public int getAdaptationPopularityThreshold() {
        return adaptationPopularityThreshold;
    }

    public void setAdaptationPopularityThreshold(int adaptationPopularityThreshold) {
        if (adaptationLengthThreshold < 2) {
            System.out.printf("WARNING: Bad adaptation popularity threshold: %d, default value of 1 will be used instead.\n",
                    adaptationPopularityThreshold);
            this.adaptationPopularityThreshold = 1;
            return;
        }
        this.adaptationPopularityThreshold = adaptationPopularityThreshold;
    }

    public int getAdaptationLengthThreshold() {
        return adaptationLengthThreshold;
    }

    public void setAdaptationLengthThreshold(int adaptationLengthThreshold) {
        if (adaptationLengthThreshold < 2) {
            System.out.printf("WARNING: Bad adaptation length threshold: %d, default value of 2 will be used instead.\n",
                    adaptationLengthThreshold);
            this.adaptationLengthThreshold = 2;
            return;
        }
        this.adaptationLengthThreshold = adaptationLengthThreshold;
    }

    public ArrayList<String> getThemeRoots() {
        return themeRoots;
    }

    public void setThemeRoots(ArrayList<String> themeRoots) {
        this.themeRoots = themeRoots;
    }

    public ArrayList<String> getFixedRoots() {
        return fixedRoots;
    }

    public void setFixedRoots(ArrayList<String> fixedRoots) {
        this.fixedRoots = fixedRoots;
    }

    public void restoreDefaults(){
        latinPageSymbolsMax = 160;
        cyrillicPageSymbolsMax = 70;
        itemsPerPageMax = 8;
        useMoreButton = false;
        morePatterns = Arrays.asList("Еще", "More", "Далее");
        morePopularityPercentThreshold = 0;
        adaptationPopularityThreshold = 1;
        adaptationLengthThreshold = 2;

        themeRoots = null;
        fixedRoots = null;
    }
}
